package com.jake.sort.utils;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

public class WeekdaySortUtils {

    public static Set<String> getOrderedWeekdaysByCurrent(String weekdayStr) {
        Set<String> weekdays = new LinkedHashSet<>();
        int weekday = Integer.valueOf(weekdayStr);
        if (weekday < 1 || weekday > 7) {
            throw new RuntimeException("weekday should be between 1 to 7");
        }

        weekdays.addAll(getWeekdaysAhead(weekday));
        weekdays.addAll(getWeekdaysRear(weekday));

        return weekdays;
    }

    private static Set<String> getWeekdaysRear(int weekday) {
        Set<String> weekdaysAfter = new HashSet<>();
        for (int i = 1; i < weekday; i++) {
            weekdaysAfter.add(String.valueOf(i));
        }
        return weekdaysAfter;
    }

    private static Set<String> getWeekdaysAhead(int weekday) {
        Set<String> weekdaysAhead = new HashSet<>();
        for (int i = weekday; i < 8; i++) {
            weekdaysAhead.add(String.valueOf(i));
        }
        return weekdaysAhead;
    }

}
